<!DOCTYPE html>
<html lang="zh_CN">

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>错题汇总</title>
	<meta name="viewport" content="initial-scale=1, maximum-scale=1">
	<!-- <link rel="shortcut icon" href="http://favicon.ico"> -->
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="viewport"
		content="width=device-width, height=device-height, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">

	<!-- 固定的css 和 common.js 的引用    -->
	<link rel="stylesheet" href="http://47.104.254.28/commonfile/css/sm.min.css">
	<link rel="stylesheet" href="http://47.104.254.28/commonfile/css/common.css">
	<script type="text/javascript" src="http://47.104.254.28/commonfile/common/common/common.js"></script>

	<!-- <link rel="stylesheet" href="../../css/sm.min.css">
	<link rel="stylesheet" href="../../css/common.css"> -->
	<!-- <script type="text/javascript" src="../../common/common/common.js"></script> -->

	<!-- <script type="text/javascript"
		src="http://47.104.254.28/commonfile/js/js/vconsole.min.js"></script>
	<script>
		var vConsole = new VConsole();
	</script> -->



	<style type="text/css">
		.page {
			background: #fff;
		}

		.buttons-tab {
			overflow-x: auto;
		}

		.error-num {
			padding: 2.2rem 0;
			text-align: center;
		}

		.error-num-text {
			font-size: 0.65rem;
			color: #999;
		}

		.error-num .num {
			font-size: 1.5rem;
		}

		.list-block {
			margin: 0;
		}

		.list-block .item-inner {
			flex-direction: column;
			align-items: flex-start;
		}

		.list-block .item-link .item-inner {
			margin: 0;
		}

		.list-block .item-title {
			font-size: 0.8rem;
		}
		.list-block .item-after {
			margin: 0;
			font-size: 0.65rem;
			color: #999;
		}
	</style>


</head>

<body>
	<div class="page-group">
		<div class="page page-current">
			<div class="content infinite-scroll infinite-scroll-bottom" data-distance="100">
				<div class="buttons-tab fixed-tab"></div>

				<div class="error-num">
					<div class="error-num-text">错题总数</div>
					<div class="num"></div>
				</div>

				<div class="list-block">
					<ul class="errorbox"></ul>
				</div>
				
				<!-- 加载提示符 -->
				<div class="infinite-scroll-preloader">
					<div class="preloader"></div>
				</div>

			</div>
		</div>
	</div>




	<!-- 固定的js引用，所有的jQuery 要用 $$ 表示 -->
	<script type="text/javascript" src="http://47.104.254.28/commonfile/js/js/jquery-1.11.1.min.js"></script>
	<script type="text/javascript">var $$ = jQuery.noConflict();</script>
	<script type='text/javascript' src='http://47.104.254.28/commonfile/zepto/zepto/zepto.min.js'
		charset='utf-8'></script>
	<script type='text/javascript' src='http://47.104.254.28/commonfile/js/js/sm.min.js' charset='utf-8'></script>

	<!-- <script type="text/javascript"
		src="../../js/js/jquery-1.11.1.min.js"></script>
	<script type="text/javascript">var $$ = jQuery.noConflict();</script>
	<script type='text/javascript'
		src='../../zepto/zepto/zepto.min.js' charset='utf-8'></script>
	<script type='text/javascript' src='../../js/js/sm.min.js'
		charset='utf-8'></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.7/js/swiper.min.js"></script> -->

	<!-- <script type='text/javascript' src='http://47.104.254.28/commonfile/js/js/sm-extend.min.js' charset='utf-8'></script> -->
	<!-- <script src="http://47.104.254.28/commonfile/js/js/swiper/swiper.min.js"></script> -->

	<script type="text/javascript">

		var loading = false;

		// 注册'infinite'事件处理函数
		$(document).on('infinite', '.infinite-scroll-bottom', function () {

			// 如果正在加载，则退出
			if (loading) return;

			// 设置flag
			loading = true;
			offset = $$('.errorbox li').length;
			getErrorQuestion();
		});

		function successCallBack(data) {
			loading = false

			if (!data.success) {
				$.toast(data.message, 1500);
			}
			if (isNotNull(data.data)) {
				let errorpaper = data.data.errorpaper
				$$('.error-num .num').html(data.data.allerrornum)

				if (errorpaper.length < limit) {
					$.detachInfiniteScroll($('.infinite-scroll'));
					// 删除加载提示符
					$('.infinite-scroll-preloader').remove();
				}

				let html = ''
				for (let val of errorpaper) {
					html += `<li data-paperid="${val.paper_id}" class="item-content item-link">
										<div class="item-media"><i class="icon icon-f7"></i></div>
										<div class="item-inner">
											<div class="item-title">${ val.title }</div>
										</div>
									</li>`

									// <div class="item-after">2道</div>
				}

				$$('.errorbox').append(html);
				$.refreshScroller();

			}
		}

		function errorCallBack(data) {
			console.log(data)
			loading = false
		}


		var limit = 15;
		var offset = $$('.errorbox li').length;
		var errType = '';

		function getPaperType() {
			net_request('get', 'api/v1/dicts', {
				type: 'paper_type'
			}, function (data) {
				if (!data.success) {
					$.toast(data.message, 1500);
				}
				if (isNotNull(data.data)) {
					let types = data.data;
					let html = '';
					for (let i = 0; i < types.length; i++) {
						let cur = ''
						if (i == 0) {
							cur = 'active';
							errType = types[i].key
							getErrorQuestion()
						} else {
							cur = '';
						}
						html += `<a data-key="${types[i].key}" class="tab-link ${cur} button">${types[i].value}</a>`
					}
					$$('.buttons-tab').html(html)
				}
			}, function (err) {
				console.log(err)
				$.toast('网络错误，请重试', 1500);
			});
		}

		$$('.errorbox').on('click', 'li', function(){
			native_goto('local/cepingbaogao_cuotijiexi?pager_id=' + $$(this).data('paperid'));
		})

		$$('.buttons-tab').on('click', 'a', function () {
			if ($$(this).data('key') == errType) {
				return false;
			}
			$$('.content').scrollTop(0)
			$$(this).addClass('active').siblings().removeClass('active');
			errType = $$(this).data('key');
			$$('.errorbox').html('')
			offset = 0;
			$.attachInfiniteScroll($('.infinite-scroll'));
			getErrorQuestion()
		})

		function getErrorQuestion() {
			var params = {
				type: errType,
				limit: limit,
				offset: offset
			}

			net_request('get', 'user/errorpaper', params, successCallBack, errorCallBack);
		}

		var isInitLoad = true

		function getParams(data) {
			isInitLoad && getPaperType()
			isInitLoad = false
		}

		$$(function () {
			$.init();
		});
	</script>
</body>

</html>